<template>
  <div id="space-homepage">
    <div class="main-container container-limited container-fluid page-holder">
      <breadcrumb/>
      <el-alert
        v-if="!space.public"
        title="当前空间为私有空间，非空间成员用户无法访问也不会出现在搜索结果中。可以在空间设置中修改空间访问权限。"
        type="warning"
      />
      <div class="flex m-t-16 flex-wrap">
        <div class="shrink-0 flex align-items-center m-t-8">
          <space-avatar :space="space" :size="64" class="shrink-0" />
          <div class="h3 m-l-16 shrink-0">{{ space.title }}</div>
          <svg-icon
            class="info m-l-5"
            :icon-name="spacePublic.icon"
            :tooltip="spacePublic.tooltip"
          />
        </div>
        <div class="flex align-items-center flex-wrap m-t-8" style="margin-left: auto;">
          <OperateButtons class="m-r-16"/>
          <VoteButtons/>
          <w-x-share
            type="Product"
            :id="space.id"
            page="pages/space/index"
            :scene="`${space.id}`"
            :share-url="space.wxShare"
            class="m-l-10"
          />
        </div>
      </div>
      <p class="indent-2 f-normal m-t-8">{{ space.desc }}</p>
      <div class="card">
        <div class="card-header">管理团队</div>
        <div class="card-content">
          <UserCards :users="admins"/>
        </div>
      </div>
      <JoinedCommunities class="m-t-16" />
      <el-row :gutter="16" class="m-t-16">
        <el-col :sm="12"><RecentDocs/></el-col>
        <el-col :sm="12"><RecentIssues/></el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import SpaceAvatar from '@/components/space-avatar';
import UserCards from '@/components/shared/UserCards';
import WXShare from '@/components/wx-share-code';
import OperateButtons from './OperateButtons';
import VoteButtons from './VoteButtons';
import RecentDocs from './RecentDocuments';
import RecentIssues from './RecentIssues';
import JoinedCommunities from './JoinedCommunities';

export default {
  name: 'SpaceHomepage', // 空间主页
  components: {
    SpaceAvatar,
    UserCards,
    WXShare,
    OperateButtons,
    VoteButtons,
    RecentDocs,
    RecentIssues,
    JoinedCommunities,
  },
  computed: {
    // 当前空间数据
    space() { return this.$store.state.currentSpace; },
    // 空间是否空开
    spacePublic() {
      if (this.space.public) return { icon: 'gitlab_earth', tooltip: this.$i.SPACE_PUBLIC };
      return { icon: 'gitlab_lock', tooltip: this.$i.SPACE_PRIVATE };
    },
    // 管理团队
    admins() {
      const users = [];
      users.push(Object.assign(this.space.owner, { level: 'owner' }));
      users.push(...this.space.adminObjs.map(admin => Object.assign(admin, { level: 'admin' })));
      return users;
    },
  },
};
</script>

<style></style>
